package LRU;

import lombok.Data;

/**
 * 节点
 *
 * @author K
 * @date 2021/7/5 上午9:39
 */
@Data
public class Node implements Comparable<Node> {

    private Object key;

    private Object value;
    /**
     * 访问时间
     */
    private long time;

    /**
     * 访问次数
     */
    private int count;

    public Node(Object key, Object value, long time, int count) {
        this.key = key;
        this.value = value;
        this.time = time;
        this.count = count;
    }


    /**
     * LFU：先比较次数，如果次数相同，再比较时间
     * LRU：直接比较时间即可
     */
    @Override
    public int compareTo(Node o) {
        int compare = Integer.compare(this.count, o.count);
        if (compare == 0) {
            return Long.compare(this.time, o.time);
        }

        return compare;
    }

}
